package com.example.firstdemo.kotlin

fun main() {
//    println(evens)
//    println(doubled)
//    println(firstLarge)
//    list1
    val res = caculate(10, 20) { a, b -> a + b }
    val res1 = caculate(10, 20) { a, b -> a * b }
    println("a+b: $res----a*b: $res1")
}

val numbers = listOf(1, 2, 3, 4, 5)

// 过滤 - 找出偶数
val evens = numbers.filter { it % 2 == 0 }  // [2, 4]

// 映射 - 每个元素加倍
val doubled = numbers.map { it * 2 }  // [2, 4, 6, 8, 10]

// 查找 - 找到第一个大于3的元素
val firstLarge = numbers.first { it > 3 }  // 4

val list1 = numbers.forEach({ println(it) })

//fun caculate(a: Int, b: Int, op: (Int, Int) -> Int): Int {
//    return op(a, b)
//}
fun caculate(a: Int, b: Int, op: (Int, Int) -> Int) = op(a, b)


